<%@ page contentType="text/html; charset=utf-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>后台管理 - 爱购物-商城</title>
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/style.css"/>
</head>
<body>
<c:import url="/static/page/manager-header-nav.jsp">
    <c:param name="nav" value="product"/>
</c:import>
<div id="position" class="wrap">
    您现在的位置：<a href="${pageContext.request.contextPath}/index">爱购物-商城</a> &gt; 管理后台 &gt; 商品分类管理
</div>
<div id="main" class="wrap clearfix">
    <c:import url="/static/page/manage-left-nav.jsp"/>
    <div class="main">
        <h2>分类管理</h2>
        <div class="manage">
            <table class="list">
                <tr>
                    <th>ID</th>
                    <th>分类名称</th>
                    <th>操作</th>
                </tr>
                <!-- 遍历父分类 -->
                <c:forEach var="ca" items="${categories}">
                    <tr>
                        <td class="first w4 c">${ca.id}</td>
                        <td>${ca.name}</td>
                        <td class="w1 c">
                            <a href="${pageContext.request.contextPath}/manage/product/category/update?id=${ca.id}">修改</a>
                            <c:if test="${empty ca.subCategories || fn:length(ca.subCategories)==0}">
                                <a href="javascript:deleteCategory(${ca.id})">删除</a>
                            </c:if>
                        </td>
                    </tr>
                    <!-- 遍历子分类 -->
                    <c:forEach var="subCa" items="${ca.subCategories}">
                        <tr>
                            <td class="first w4 c">${subCa.id}</td>
                            <td class="childClass">|——${subCa.name}</td>
                            <td class="w1 c">
                                <a href="${pageContext.request.contextPath}/manage/product/category/update?id=${subCa.id}">修改</a>
                                <a href="javascript:deleteCategory(${ca.id})">删除</a>
                            </td>
                        </tr>
                    </c:forEach>
                </c:forEach>
            </table>
        </div>
    </div>
</div>
<c:import url="/static/page/footer.jsp"/>
<script>
    function deleteCategory(id) {
        if (confirm("确定要删除该分类么？")) {
            location.href = "${pageContext.request.contextPath}/manage/product/category/delete?id=" + id;
        }
    }
</script>
</body>
</html>

